package com.david.viewtest

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.david.viewtest.view.SlideCellView
import com.david.viewtest.view.SlideRecyclerView

class SlideRecyclerTestActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_selider_test)
        findViewById<SlideRecyclerView>(R.id.slide_recycler).adapter = SliderAdapter()
    }

    inner class SliderAdapter: RecyclerView.Adapter<SliderHolder>(){
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SliderHolder {
            return SliderHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_slider, parent, false) as SlideCellView)
        }

        override fun getItemCount(): Int {
            return 50
        }

        override fun onBindViewHolder(holder: SliderHolder, position: Int) {
            //bindView时调用此方法防止item复用导致动画执行错乱
            holder.item.closeMenuWithOutAnim()
        }
    }
    inner class SliderHolder(var item: SlideCellView): ViewHolder(item) {
        init {
            item?.let {
                //无二次确认时
                it.confirmFirstClickFunc = {}
                it.confirmSecondClickFunc = {}


                it.menuBtnClickFunc = { view ->
                    when(view.id) {
                        //R.id.set_top -> {}
                        //R.id.make_read -> {}
                        //R.id.delete -> {}//不需要二次确认时 delete按钮点击事件走此处
                    }
                }

                it.viewLongClickFunc = {}
            }
        }
    }
}